import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {//设置全局访问的state
        zangw: 2, // 1为藏文
        crumbs: "首页",
        userid: null,
        type: null,
        user: null,
        permission: null,
        //设置的初始属性值
        newStorge: {},
        tzxtsz: null,
        token: null,
        // userid:null,
        headImg: null,

        //图片地址
        // pathimg:'https://bbgy.cpzsyun.com:82/api/file/show/',
        pathimg: 'https://bbgy.cpzsyun.com:82/api/plant/file/show/',
        // uploadImgurl:'http://39.96.59.234:8884',
        // uploadImgurl:'https://bbgy.cpzsyun.com:82/api/plant',
        uploadImgurl: 'https://bbgy.cpzsyun.com:82/api/plant',
        imageUrls: 'https://bbgy.cpzsyun.com:82/api/plant/file/show/',
        // imageUrls:'https://bbgy.cpzsyun.com:82/api/file/show/',
        // pathurl:'http://192.168.0.100:8880/',
        // plantImg:'https://bbgy.cpzsyun.com:82/api//plant/file/show/',
        plantImg: 'https://bbgy.cpzsyun.com:82/api/plant/file/show/',
        //  追溯查询请求域名
        pathurl: 'https://bbgy.cpzsyun.com:82/api/',
        upload: "https://bbgy.cpzsyun.com:82/api/plant/file/upload",
        num: 0,
        storName: '',
        system: null,
        TabStatus: null,
        logozImg: '',
        logoimg: ''
    },
    getters: {//实时监听state值得变化
        logoimg(state) {
            if (!state.logoimg) {
                state.logoimg = JSON.parse(sessionStorage.getItem("logoimg"))
            }
            return state.logoimg
        },
        logozImg(state) {
            if (!state.logozImg) {
                state.logozImg = JSON.parse(sessionStorage.getItem("logozImg"))
            }
            return state.logozImg
        },
        user(state) {
            // console.log(1)
            if (!state.user) {
                state.user = JSON.parse(sessionStorage.getItem("key"))
            }
            console.log(state.user)
            return state.user
        },
        headImg(state) {
            if (!state.headImg) {
                state.headImg = JSON.parse(sessionStorage.getItem("headImg"))
            }
            return state.headImg
        },
        // permission(state){
        //     if(!state.permission){
        //         state.permission = JSON.parse(sessionStorage.getItem("permission"))
        //     }
        //     return state.permission
        // },
        tzxtsz(state) {
            if (!state.tzxtsz) {
                state.tzxtsz = JSON.parse(sessionStorage.getItem('tzxtsz'))
            }
        },
        token(state) {
            if (!state.token) {
                state.token = JSON.parse(sessionStorage.getItem('token'))
            }
            return state.token
        },
        system(state) {
            if (!state.system) {
                state.system = JSON.parse(sessionStorage.getItem('permission'))
            }
            return state.system
        },
        TabStatus(state) {
            if (!state.TabStatus) {
                state.TabStatus = JSON.parse(sessionStorage.getItem('TabStatus'))
            }
            return state.TabStatus
        },
        // userid(state){
        //     if(!state.userid){
        //         state.userid = JSON.parse(localStorage.getItem('userid'))
        //         console.log(JSON.parse(localStorage.getItem('userid')))
        //     }
        //     return state.userid
        // }
    },
    mutations: {//唯一允许改变state
        setlogoimg(state, v) {
            state.logoimg = v
            sessionStorage.setItem("logoimg", JSON.stringify(v))
        },
        setlogozImg(state, v) {
            state.logozImg = v
            sessionStorage.setItem("logozImg", JSON.stringify(v))
        },
        setTabStatus(state, v) {
            state.TabStatus = v
            sessionStorage.setItem("TabStatus", JSON.stringify(v))
        },
        setsystem(state, v) {
            state.system = v
            sessionStorage.setItem("permission", JSON.stringify(v))
        },
        setuserid(state, v) {
            state.userid = v
            localStorage.setItem("userid", JSON.stringify(v))
        },
        settoken(state, v) {
            state.token = v
            sessionStorage.setItem("token", JSON.stringify(v))
            localStorage.setItem("token", JSON.stringify(v))
        },
        setCrumbs(state, v) {
            state.crumbs = v
        },

        setname(state, v) {
            state.user = v
            sessionStorage.setItem("key", JSON.stringify(v))
        },

        setpermission(state, v) {
            state.permission = v
            sessionStorage.setItem("permission", JSON.stringify(v))
        },
        removename(state, v) {
            state.user = null
            sessionStorage.removeItem("key")
        },
        setStorge(state, v) {
            state.newStorge = v
        },

        settzxtsz(state, v) {
            state.tzxtsz = v
            sessionStorage.setItem("tzxtsz", JSON.stringify(v))
        },


        setnum(state, v) {
            state.num = v
        },
        settype(state, v) {
            state.type = v
        },
        // 设置类型
        setStorName(state, v) {
            state.storName = v

        },
        removeRuform(state, v) {
            state.newStorge = null
        },
        // 设置分页
        // setPagNum(state,v){
        //     state.pagNum = v
        // }
    },
    actions: {//触发更改

    },

})

export default store
